﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class ViewDuplicateConnections : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");
            else
            {
                GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
                OnlineUser ou = (OnlineUser)Session["User"];
                if (ou.UserAccessLevel != ("5"))
                {
                    Response.Redirect("~/Default.aspx");
                }


                if (!IsPostBack)
                {
                    string TestedUser = null;
                    if (Request.QueryString["UserId"] != null)
                    {
                        TestedUser = Request.QueryString["UserId"];
                        SimilarConnectionsDataSource.SelectParameters.Add("UserId", TestedUser);
                        UserDetailsDS.SelectParameters.Add("UserId", TestedUser);
                        UserLoginsDS.SelectParameters.Add("UserId", TestedUser);
                        UserPageHyperlink.NavigateUrl = "~/UserPage.aspx?Id=" + TestedUser;
                        UserPageHyperlink.Text = GND.ReadNivdalStringData("UserId", "Nivdal_GetUserNameById", TestedUser);
                        ChatsDataSource.SelectParameters.Add("UserId", TestedUser);
                        ChatsPanel.Visible = (ou.UserAccessLevel == "5");
                        SuspiciousTransfersDataSource.SelectParameters.Add("UserId", TestedUser);
                    }
                    else
                        Response.Redirect("~/Default.aspx");
                }
            }

        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }

        protected string GetCountryByIP(object IP)
        {
            //string ReturnVaue = "Sevice1: ";
            string ReturnVaue = "";
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            decimal CountryId = GetNivdalData.GetNivdalData.GetIPCountry(IP.ToString());

            if (CountryId > 10)
            {
                ReturnVaue += GND.ReadNivdalStringData("CountryId", "Nivdal_GetCountryNameByIdProc", CountryId.ToString());

            }
            else
            {
                ReturnVaue += "unknown";
            }
            //ReturnVaue += "<br /> Service2:";

            //CountryId = GetNivdalData.GetNivdalData.GetIpCountryV2(IP.ToString());

            //if (CountryId > 10)
            //{
            //    ReturnVaue += GND.ReadNivdalStringData("CountryId", "Nivdal_GetCountryNameByIdProc", CountryId.ToString());

            //}
            //else
            //{
            //    ReturnVaue += "unknown";
            //}
            return (ReturnVaue);
        }
    }
}